﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
namespace Day2
{
    public partial class NotePadPage : PhoneApplicationPage
    {
        public NotePadPage()
        {
            InitializeComponent();
        }

        private void bntSaveSetting_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
			setting.Remove("notepad.dat");
			setting.Add("notepad.dat",txtBody.Text);
			setting.Save();
			
			//txtBody.Text = setting["notepad.dat"];
			
        }

        private void bntLoadSetting_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;		
			txtBody.Text = (string) setting["notepad.dat"];
        }

        private void bntSaveFile_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
			
			IsolatedStorageFileStream stream = isf.CreateFile("notepad.txt");
			
			StreamWriter writer = new StreamWriter(stream);
        	writer.Write(txtBody.Text);
			writer.Close();
		}

        private void bntLoadFile_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
			
			IsolatedStorageFileStream stream = isf.OpenFile("notepad.txt",FileMode.Open);
			
			StreamReader reader = new StreamReader(stream);
			txtBody.Text = reader.ReadToEnd();
			reader.Close();
        }

        private void ApplicationBarIconButton_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
        }

        private void ApplicationBarMenuItem_Click(object sender, System.EventArgs e)
        {
        	// TODO: Add event handler implementation here.
        }
    }
}
